package com.global.college.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.global.college.R;
import com.global.college.base.BaseActivity;
import com.global.college.constants.Constant;
import com.global.college.ui.bean.MyOrderDetail;
import com.global.college.ui.bean.MyOrderListModel;
import com.global.college.ui.interfaces.IOrderView;
import com.global.college.ui.presenter.OrderPresenter;
import com.global.college.utils.StringUtils;
import com.global.college.widget.FrescoImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 订单详情
 */
public class OrderDetailActivity extends BaseActivity implements IOrderView {

    @BindView(R.id.fiv_cover)
    FrescoImageView fivCover;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_num)
    TextView tvNum;
    @BindView(R.id.tv_total_price)
    TextView tvTotalPrice;
    @BindView(R.id.tv_discount_price)
    TextView tvDiscountPrice;
    @BindView(R.id.tv_real_price)
    TextView tvRealPrice;
    @BindView(R.id.ll_real_price)
    LinearLayout llRealPrice;
    @BindView(R.id.tv_order_num)
    TextView tvOrderNum;
    @BindView(R.id.ll_order_num)
    LinearLayout llOrderNum;
    @BindView(R.id.tv_order_create_time)
    TextView tvOrderCreateTime;
    @BindView(R.id.ll_order_create_time)
    LinearLayout llOrderCreateTime;
    @BindView(R.id.tv_order_pay_time)
    TextView tvOrderPayTime;
    @BindView(R.id.ll_order_pay_time)
    LinearLayout llOrderPayTime;
    @BindView(R.id.tv_order_cancle_time)
    TextView tvOrderCancleTime;
    @BindView(R.id.ll_order_cancle_time)
    LinearLayout llOrderCancleTime;
    private OrderPresenter orderPresenter;
    private String orderId;

    @Override
    public int getContentViewId() {
        return R.layout.activity_order_detail;
    }

    @Override
    public void onCreateNew(Bundle savedInstanceState) {
        setShowTitleBar(false);
        orderId = getIntent().getStringExtra(Constant.Key.NAME);
        orderPresenter = new OrderPresenter(this);
        orderPresenter.setOrderView(this);
        orderPresenter.getOrderDetail(orderId);
    }

    @Override
    public void getInitData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        useImmersionBar = false;
        super.onCreate(savedInstanceState);
    }

    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    @Override
    public void onGetOrderListSuccess(MyOrderListModel object) {

    }

    @Override
    public void onGetOrderListFail(String error) {

    }

    @Override
    public void onGetOrderDetailSuccess(MyOrderDetail myOrderDetail) {
        if (null != myOrderDetail) {
            UpdateUI(myOrderDetail);
        }

    }

    private void UpdateUI(MyOrderDetail myOrderDetail) {
        fivCover.setImageURI(myOrderDetail.getGoodCover());
        tvTitle.setText(myOrderDetail.getGoodName());
        tvPrice.setText("¥" + StringUtils.getPrice2(String.valueOf(myOrderDetail.getOrderPrice())));
        tvNum.setText("x1");
        //商品类型，1课程2训练营
        switch (myOrderDetail.getGoodType()) {
            case "1":
                tvType.setText("课程");
                break;
            case "2":
                tvType.setText("训练营");
                break;
        }


        tvTotalPrice.setText("¥" + StringUtils.getPrice2(String.valueOf(myOrderDetail.getGoodPrice())));
        tvDiscountPrice.setText("¥" + StringUtils.getPrice2(String.valueOf(myOrderDetail.getGoodPreferentialPrice())));
        tvRealPrice.setText("¥" + StringUtils.getPrice2(String.valueOf(myOrderDetail.getOrderPrice())));
        tvOrderNum.setText(myOrderDetail.getOrderId() + "");
        tvOrderCreateTime.setText(myOrderDetail.getCreateTime() + "");
        tvOrderPayTime.setText(myOrderDetail.getPayCompleteTime() + "");
        tvOrderCancleTime.setText(myOrderDetail.getCancelTime() + "");
        //订单状态默认0未支付，1支付完成，2取消的
        switch (myOrderDetail.getOrderState()) {
            case 0:
            case 1:
                llOrderCancleTime.setVisibility(View.GONE);
                llOrderPayTime.setVisibility(View.VISIBLE);
                llRealPrice.setVisibility(View.VISIBLE);
                break;
            case 2:
                llOrderCancleTime.setVisibility(View.VISIBLE);
                llOrderPayTime.setVisibility(View.GONE);
                llRealPrice.setVisibility(View.GONE);
                break;
        }

    }

    @Override
    public void onGetOrderDetailFail(String error) {

    }

    @Override
    public void onCreateOrderSuccess(Object smsModel) {

    }

    @Override
    public void onCreateOrderFail(String error) {

    }

    @Override
    public void onCancleOrderSuccess(Object smsModel) {

    }

    @Override
    public void onCancleOrderFail(String error) {

    }
}